<template>
	<view class="page">
		<view class="pageBg">
			<image src="https://bjsx.gzwhir.com/admin-api/infra/file/18/get/memberbg2.jpg" mode="aspectFill"></image>
		</view>
		<view class="flex0">
			<u-navbar :fixed='false' bgColor="transparent" @leftClick="navBack" title="设置">
				<view slot="center" class="navTitle">设置</view>
			</u-navbar>
		</view>
		<view class="flex1">
			<scroll-view scroll-y="true" class="scrollView">
				<view class="pd30">
					<view class="vMenus">
						<view v-for="(item,index) in dataList" :key="index" @click="toInfo(item)"
							class="i navigator">
							<view class="p">{{item.name}}</view>
							<view class="rico">
								<image src="@/static/images/icon-more.svg" mode="aspectFit"></image>
							</view>
						</view>
						<navigator url="" open-type="navigate" class="i navigator">
							<view class="p">留言反馈</view>
							<view class="rico">
								<image src="@/static/images/icon-more.svg" mode="aspectFit"></image>
							</view>
						</navigator>
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="fbtns" v-if="isLogin">
			<view class="btn" @tap="logout">
				退出登录
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isLogin:false,
				dataList: []
			}
		},
		onLoad() {
			
			if (this.$db.get("userToken")) {
				this.$api.memberInfo({}, res => {
					if (res.code == 200) {
						this.isLogin = true
					}
				})
			
			}
				this.$api.articleCate({
					parentId: 8
				}, res => {
					if (res.code == 200) {
						this.dataList = res.data;
					}
				})
		},
		methods:{
			logout() {
				
				//清除本地缓存数据
				uni.clearStorage();
				
				this.$common.successToShow('退出成功', ress => {
					
					uni.redirectTo({
						url: '/subpage/login/login'
					});
				})
			},
			toInfo(item){
				
				this.$api.articleList({
					categoryId: item.id,
					pageNo:1,
				}, res => {
					if (res.code == 200) {
						if(res.data.list){
							if(res.data.list.length==1){
								
									uni.navigateTo({
										url:'/subpage/single/single?id='+res.data.list[0].id
									})
							}else{
								uni.navigateTo({
									url:'/subpage/article/list?id='+item.id
								})
							}
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.fbtns {
		padding: 0 30rpx 60rpx;

		.btn {
			font-size: 28rpx;
			text-align: center;
			line-height: 90rpx;
			border-radius: 90rpx;
			background: #fff;
			color: #65554d;
		}
	}
</style>